<?php
namespace app\common\model;

class HistoryQuestionDate extends Base
{
    /**
     * getListByCourseIds
     * @param array $courseIds
     * @return array
     * @throw
     */
    public function getListByCourseIds(array $courseIds): array
    {
        // 查询条件
        $where = [
            ['course_id', 'in', $courseIds]
        ];

        // 输出字段
        $field = "id,name,course_id,date_format(date,'%Y年%m月') as date";

        // 查询数据
        $list = $this->where($where)->field($field)->order('date', 'desc')->cache(false)->select();

        // 处理数据
        foreach ($list as $k => $v)
        {
            if (!$v['name'])
            {
                $list[$k]['name'] = $v['date'];
            }
        }

        // 返回
        return $list ? $list->toArray() : [];
    }
}